package dyyx.dto;

import java.io.IOException;
import java.time.LocalDateTime;

import org.apache.commons.lang3.StringUtils;

import com.aerospike.client.AerospikeClient;
import com.aerospike.client.Host;
import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.policy.ClientPolicy;

public class AsClient{

	public final IAerospikeClient client;

	// public final String name;
	public final String connectString;
	
	public final String createTime ;

	
	
	

	
	public AsClient(String connectString)throws IOException{

		this.connectString = connectString;
		ClientPolicy clientPolicy = new ClientPolicy();
		String[]arr = StringUtils.split(connectString, ":");
		if(arr==null || arr.length!=2) {
			throw new RuntimeException("host format error");
		}
		Host host = new Host(arr[0], Integer.parseInt(arr[1]));	
		IAerospikeClient clientTmp = new AerospikeClient(clientPolicy, host);

		this.client = clientTmp;
		this.createTime = LocalDateTime.now().toString();
		
	}
	
	@Override
	public String toString() {
		return connectString+","+createTime+","+client+",conntected="+client.isConnected();
	}

}
